package cn.px.office.vo;

import cn.px.office.enums.ExcelDataTypeEnum;
import cn.px.office.poi.excel.entity.params.ExcelRowParams;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Workbook;

import java.util.HashMap;
import java.util.Map;
import java.util.function.Function;

/**
 * @Description
 * @author 品讯科技
 * @date 2024-08
 * @Version Copyright (c) 2019,北京乾元坤和科技有限公司 All rights reserved.
 */
public class ExcelData {

    /**
     * 前台或者序号使用
     */
    private Object key;

    /**
     * 类型：
     * 1.正常实体
     * 2.自定义
     * 3.自定义
     */
    private Integer type;

    /**
     * 数据项
     * 1.表示实体
     * 2.自定义：Map<Integer, CustomCell>:Integer表示第几列，CustomCell表示该列的属性，0开始
     * 3.自定义：Map<String, CustomCell>:String表示列名称
     */
    private Object data;

    /**
     * 该行合并单元格信息
     * 在正常VO中是不需要处理的，直接支持
     */
    private Map<Object, CustomMerge> mergeMap;

    /**
     * 自定义列样式
     * 该样式会覆盖一切样式
     */
    private Function<Workbook, CellStyle> cellStyle;

    /**
     * 行属性
     */
    private ExcelRowParams excelRowParams;

    public ExcelData() {
        this.type = ExcelDataTypeEnum.TYPE_VO.getValue();
        this.mergeMap = new HashMap<>();
    }

    public ExcelData(ExcelDataTypeEnum typeEnum) {
        this.type = typeEnum.getValue();
        this.mergeMap = new HashMap<>();
    }

    public ExcelData(Object data) {
        this.type = ExcelDataTypeEnum.TYPE_VO.getValue();
        this.data = data;
        this.mergeMap = new HashMap<>();
    }

    public ExcelData(ExcelDataTypeEnum typeEnum, Object data) {
        this.type = typeEnum.getValue();
        this.data = data;
        this.mergeMap = new HashMap<>();
    }

    public ExcelData(Object data, Map<Object, CustomMerge> mergeMap) {
        this.type = ExcelDataTypeEnum.TYPE_VO.getValue();
        this.data = data;
        this.mergeMap = mergeMap;
    }

    public ExcelData(ExcelDataTypeEnum typeEnum, Object data, Map<Object, CustomMerge> mergeMap) {
        this.type = typeEnum.getValue();
        this.data = data;
        this.mergeMap = mergeMap;
    }

    public Integer getType() {
        return type;
    }

    public ExcelData setType(Integer type) {
        this.type = type;
        return this;
    }

    public Object getData() {
        return data;
    }

    public ExcelData setData(Object data) {
        this.data = data;
        return this;
    }

    public ExcelData addMerge(Object key, CustomMerge merge) {
        this.mergeMap.put(key, merge);
        return this;
    }

    public ExcelData addMerge(Object key, Integer rowIndex, Integer cellIndex) {
        this.mergeMap.put(key, new CustomMerge(key, rowIndex, cellIndex));
        return this;
    }

    public ExcelData addAllMerge(Map<Object, CustomMerge> mergeMap) {
        this.mergeMap.putAll(mergeMap);
        return this;
    }

    public Map<Object, CustomMerge> getMergeMap() {
        return mergeMap;
    }

    public Object getKey() {
        return key;
    }

    public ExcelData setKey(Object key) {
        this.key = key;
        return this;
    }

    public Function<Workbook, CellStyle> getCellStyle() {
        return cellStyle;
    }

    public ExcelData setCellStyle(Function<Workbook, CellStyle> cellStyle) {
        this.cellStyle = cellStyle;
        return this;
    }

    public ExcelRowParams getExcelRowParams() {
        return excelRowParams;
    }

    public ExcelData setExcelRowParams(ExcelRowParams excelRowParams) {
        this.excelRowParams = excelRowParams;
        return this;
    }
}
